import angular from 'angular';
/**
 * zhx.media.review Service
 * Author: Vicco Wang
 * Date: 2017/10/18
 * Version : 1.0.0
 *
 */
angular.module('zhx.media.review').factory('zhxMediaReview.util',()=>{
    let utils = {};

    /**
     * 获取渲染区域大小,获取方式始终保证可视区域不会移除当前窗体;
     * @returns {{width: number, height: number}}
     */
    utils.getCurrentSize = () => {
        const docWidth = document.documentElement.clientWidth,
            docHeight = document.documentElement.clientHeight;
        let isDocWidth = docHeight > docWidth * 9 / 16;
        return {
            width : isDocWidth? docWidth : docHeight * 16 / 9,
            height :isDocWidth? docWidth * 9 / 16 : docHeight
        };
    };

    return utils;
});

angular.module('zhx.media.review').factory('zhxMediaReview.service',['$q', ($q) => {

    let service = {};
    /**
     * 回放列表数组,按顺序播放内容,包含图片与视频
     * @type {Array}
     */
    service.playbackList = [];
    /**
     * 当前正在播放的内容
     * @type {null}
     */
    service.playingContent = null;
    /**
     * 设置全局播放列表
     * @param list
     */
    service.setPlaybackList = (list) => { service.playbackList = list };
    /**
     * 获取初始播放列表
     */
    service.getRawPlaybackList = () => ( service.playbackList );
    /**
     * 获取一个深度复制的播放列表,该列表的修改不会影响原始列表
     */
    service.getPlaybackList = () => ( angular.copy(service.playbackList) );
    /**
     * 获取当前正在播放内容
     */
    service.getPlayingContent = () => ( service.playingContent );
    /**
     * 根据数据构建每一个播放内容,绑定播放事件;
     */
    service.constructPlayContent = (playContent) => {

    };
    /**
     * 根据数据构建播放列表,播放列表中的内容都是重构过的播放内容
     */
    service.constructPlayList = (playList) => {
        if( angular.isArray(playList) ){
            for( let i = 0; i < playList.length; i++ ){
                let playObject = playList[i];
                //初始化当前播放对象为 未播放状态;
                playObject.played = false;
                playObject.setPlayStatus = (boolean) => {
                    playObject.played = boolean;
                };
                playObject.getPlayStatus = () => (playObject.played);
            }
        }
        return playList;
    };

    return service;

}]);